package org.flowcircuit.utils

object Property {

  def apply[T]( listener : Function0[Unit] ) = new Property[T]( null.asInstanceOf[T], listener )

  implicit def property2type[T](property : Property[T]) : T = property.apply
}

/**
 * A property allowing callback when the property is changed.
 */
case class Property[T]( var value : T, listener : Function0[Unit] ) {

  def apply : T = value

  def update( newvalue : T ) {
    value = newvalue
    if (listener != null) listener()
  }

  override def toString = value.toString
}